"ui";
ui.statusBarColor("#3640A9"); //通知栏颜色
ui.layout(
    <vertical>
        <appbar>
            <toolbar id="toolbar" title="一言"bg="#3640A9" />
        </appbar>
        <vertical id="ver1" visibility="visible">
            <progressbar id="jdt" w="*"h="25"margin="10 0 10 0"  indeterminate="true" style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"/>
            <text text="请等待..."margin="20 15 0 0" h="auto"textSize="16"/>
        </vertical>
        <vertical id="ver2"visibility="gone">
            <button id="but" paddingLeft="26"text=" " gravity="left|center" style="Widget.AppCompat.Button.Borderless"textStyle="normal" w="*"h="120"textSize="16"/>
                <horizontal>
                    <text text="点击文字即可复制"margin="20 15 0 0" h="auto"textSize="14"/>
                    <button id="sx" text="点我刷新"margin="8 15 0 0" textColor="#737373"style="Widget.AppCompat.Button.Borderless" w="auto"/>
                </horizontal>
        </vertical>
    </vertical>
);

ui.but.on("click", () => {
    setClip(ui.but.text());
    toast("复制成功");
});

ui.sx.on("click", () => {
    (function ok() {
        threads.start(function() {
            try {
                ui.run(() => {
                    ui.ver1.attr('visibility', 'visible');
                    ui.ver2.attr('visibility', 'gone');
                    var data = http.get('https://v1.hitokoto.cn/', {});
                    ui.but.setText(data.body.json().hitokoto);
                    ui.ver1.attr('visibility', 'gone');
                    ui.ver2.attr('visibility', 'visible');
                });
            } catch (e) {
                ok();
            };
        });
    })();
});

threads.start(function() {
    ui.run(() => {
        var data = http.get('https://v1.hitokoto.cn/',{});
        ui.but.setText(data.body.json().hitokoto);
        ui.ver1.attr('visibility', 'gone');
        ui.ver2.attr('visibility', 'visible');
    });
});



